// utils/emailService.js
const nodemailer = require('nodemailer');
const config = require('../config/emailConfig');

// 双重验证环境变量
if (!process.env.EMAIL_USER || !process.env.EMAIL_PASS) {
  throw new Error('SMTP认证信息未配置!');
}

const transporter = nodemailer.createTransport(config);

// 验证连接
transporter.verify(function(error, success) {
  if (error) {
    console.error('SMTP连接验证失败:', error);
  } else {
    console.log('SMTP服务已就绪');
  }
});

module.exports = transporter;
